package org.wu.framework.log.platform.infrastructure.persistence;

import org.wu.framework.log.platform.infrastructure.entity.RunLogDO;
import org.wu.framework.log.platform.infrastructure.converter.RunLogConverter;
import org.wu.framework.log.platform.infrastructure.mapper.RunLogMapper;
import org.wu.framework.log.platform.domain.model.run.log.RunLogRepository;
import org.springframework.stereotype.Repository;
import java.util.stream.Collectors;
import org.wu.framework.lazy.orm.database.lambda.stream.wrapper.LazyWrappers;
import org.wu.framework.web.response.Result;
import org.wu.framework.web.response.ResultFactory;
import jakarta.annotation.Resource;
import org.wu.framework.log.platform.domain.model.run.log.RunLog;
import org.wu.framework.lazy.orm.database.lambda.stream.lambda.LazyLambdaStream;
import java.util.List;
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
/**
 * describe 运行日志 
 *
 * @author Jia wei Wu
 * @date 2024/03/24 01:02 下午
 * @see org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyInfrastructurePersistence 
 **/
@Repository
public class RunLogRepositoryImpl  implements  RunLogRepository {

    @Resource
    LazyLambdaStream lazyLambdaStream;

    /**
     * describe 新增运行日志
     *
     * @param runLog 新增运行日志     
     * @return {@link Result<RunLog>} 运行日志新增后领域对象     
     
     * @author Jia wei Wu
     * @date 2024/03/24 01:02 下午
     **/

    @Override
    public Result<RunLog> story(RunLog runLog) {
        RunLogDO runLogDO = RunLogConverter.INSTANCE.fromRunLog(runLog);
        lazyLambdaStream.upsert(runLogDO);
        return ResultFactory.successOf();
    }

    /**
     * describe 批量新增运行日志
     *
     * @param runLogList 批量新增运行日志     
     * @return {@link Result<List<RunLog>>} 运行日志新增后领域对象集合     
     
     * @author Jia wei Wu
     * @date 2024/03/24 01:02 下午
     **/

    @Override
    public Result<List<RunLog>> batchStory(List<RunLog> runLogList) {
        List<RunLogDO> runLogDOList = runLogList.stream().map(RunLogConverter.INSTANCE::fromRunLog).collect(Collectors.toList());
        lazyLambdaStream.upsert(runLogDOList);
        return ResultFactory.successOf();
    }

    /**
     * describe 查询单个运行日志
     *
     * @param runLog 查询单个运行日志     
     * @return {@link Result<RunLog>} 运行日志领域对象     
     
     * @author Jia wei Wu
     * @date 2024/03/24 01:02 下午
     **/

    @Override
    public Result<RunLog> findOne(RunLog runLog) {
        RunLogDO runLogDO = RunLogConverter.INSTANCE.fromRunLog(runLog);
        RunLog runLogOne = lazyLambdaStream.selectOne(LazyWrappers.lambdaWrapperBean(runLogDO), RunLog.class);
        return ResultFactory.successOf(runLogOne);
    }

    /**
     * describe 查询多个运行日志
     *
     * @param runLog 查询多个运行日志     
     * @return {@link Result<List<RunLog>>} 运行日志领域对象     
     
     * @author Jia wei Wu
     * @date 2024/03/24 01:02 下午
     **/

    @Override
    public Result<List<RunLog>> findList(RunLog runLog) {
        RunLogDO runLogDO = RunLogConverter.INSTANCE.fromRunLog(runLog);
        List<RunLog> runLogList = lazyLambdaStream.selectList(LazyWrappers.lambdaWrapperBean(runLogDO), RunLog.class);
        return ResultFactory.successOf(runLogList);
    }

    /**
     * describe 分页查询多个运行日志
     *
     * @param size 当前页数
     * @param current 当前页
     * @param runLog 分页查询多个运行日志     
     * @return {@link Result<LazyPage<RunLog>>} 分页运行日志领域对象     
     
     * @author Jia wei Wu
     * @date 2024/03/24 01:02 下午
     **/

    @Override
    public Result<LazyPage<RunLog>> findPage(int size,int current,RunLog runLog) {
        RunLogDO runLogDO = RunLogConverter.INSTANCE.fromRunLog(runLog);
        LazyPage<RunLog> lazyPage = new LazyPage<>(current,size);
        LazyPage<RunLog> runLogLazyPage = lazyLambdaStream.selectPage(LazyWrappers.lambdaWrapperBean(runLogDO),lazyPage, RunLog.class);
        return ResultFactory.successOf(runLogLazyPage);
    }

    /**
     * describe 删除运行日志
     *
     * @param runLog 删除运行日志     
     * @return {@link Result<RunLog>} 运行日志     
     
     * @author Jia wei Wu
     * @date 2024/03/24 01:02 下午
     **/

    @Override
    public Result<RunLog> remove(RunLog runLog) {
        RunLogDO runLogDO = RunLogConverter.INSTANCE.fromRunLog(runLog);
        //  lazyLambdaStream.delete(LazyWrappers.lambdaWrapperBean(runLogDO));
        return ResultFactory.successOf();
    }

    /**
     * describe 是否存在运行日志
     *
     * @param runLog 运行日志领域对象     
     * @return {@link Result<Boolean>} 是否存在 true 存在，false 不存在     
     
     * @author Jia wei Wu
     * @date 2024/03/24 01:02 下午
     **/

    @Override
    public Result<Boolean> exists(RunLog runLog) {
        RunLogDO runLogDO = RunLogConverter.INSTANCE.fromRunLog(runLog);
        Boolean exists=lazyLambdaStream.exists(LazyWrappers.lambdaWrapperBean(runLogDO));
        return ResultFactory.successOf(exists);
    }

}